package com.zznj.xzjc.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.zznj.xzjc.R;
import com.zznj.xzjc.base.BaseActivity;
import com.zznj.xzjc.event.EventTag;
import com.zznj.xzjc.event.MessageEvent;
import com.zznj.xzjc.net.SharedHelper;
import com.zznj.xzjc.net.entity.BaseBean;
import com.zznj.xzjc.net.entity.DiaoChaQuZhengBean;
import com.zznj.xzjc.net.entity.LoginBean;
import com.zznj.xzjc.net.rxjava.HttpMethods;
import com.zznj.xzjc.net.subscribers.ProgressSubscriber;
import com.zznj.xzjc.net.subscribers.SubscriberOnNextListener;
import com.zznj.xzjc.view.MaxHeightRecyclerView;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.Unbinder;
import okhttp3.FormBody;

/**
 * 描述：线索发现
 */
public class ActivityZnyjJine extends BaseActivity {


    Unbinder unbinder;



    @BindView(R.id.searchEdit)
    EditText searchEdit;
    @BindView(R.id.searchBtn)
    ImageView searchBtn;

    @BindView(R.id.xzhj_linear)
    View xzhj_linear;
    @BindView(R.id.xzhj_hj_tv)
    TextView xzhj_hj_tv;
    @BindView(R.id.xzhj_hj_tv_xx)
    ImageView xzhj_hj_tv_xx;
    @BindView(R.id.xzhjtcLinear)
    View xzhjtcLinear;
    @BindView(R.id.xzhjList)
    RecyclerView xzhjList;
    @BindView(R.id.fyhjList)
    RecyclerView fyhjList;


    @BindView(R.id.xzqh_linear)
    View xzqh_linear;
    @BindView(R.id.xzqh_tv)
    TextView xzqh_tv;
    @BindView(R.id.xzqh_tv_xx)
    ImageView xzqh_tv_xx;
    @BindView(R.id.areaList)
    RecyclerView areaList;


    @BindView(R.id.lrdw_linear)
    View lrdw_linear;
    @BindView(R.id.lrdw_tv)
    TextView lrdw_tv;
    @BindView(R.id.lrdw_tv_xx)
    ImageView lrdw_tv_xx;
    @BindView(R.id.lrdwList)
    MaxHeightRecyclerView lrdwList;



    @BindView(R.id.srl_all)
    SmartRefreshLayout srlAll;
    @BindView(R.id.rec_main)
    RecyclerView rec_main;

    @BindView(R.id.bottomLinear)
    View bottomLinear;
    @BindView(R.id.tishiImg)
    ImageView tishiImg;


    @BindView(R.id.zheCeng)
    View zheCeng;

    @Override
    protected int getLayoutId() {
        return R.layout.gyss_activity_znyjjine_layout;
    }

    private LoginBean user;

    @Override
    public void initView() {
        user = new Gson().fromJson(SharedHelper.readValueByKeyForString(mContext, "Member"), LoginBean.class);
        setTitle("执行金额预警");
        initSrl();
    }

    @Override
    protected void initData() {

    }

    private void initSrl() {
        srlAll.setEnableRefresh(true);
        srlAll.setEnableLoadMore(true);
        srlAll.setEnableAutoLoadMore(true);
        srlAll.setOnRefreshListener(refresh_layout -> {
            refresh();
        });
        srlAll.setOnLoadMoreListener(refresh_layout -> {
            isShowDialog = false;
            page++;
            getData();
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refreshData(MessageEvent messageEvent) {
        if (messageEvent.getTag().equals(EventTag.DT)) {
            refresh();
        }
    }

    private boolean isShowDialog = true;
    private int page = 0;
    private List<Object> lcjdListData = new ArrayList<>();
    public void refresh() {
        srlAll.setEnableLoadMore(true);
        isShowDialog = false;
        page = 1;
        srlAll.setEnableLoadMore(true);
        lcjdListData.clear();
        bottomLinear.setVisibility(View.GONE);
//        mAdapter.notifyDataSetChanged();
        getData();
    }

    private void getData() {
        SubscriberOnNextListener<BaseBean<List<DiaoChaQuZhengBean>>> onNextListener = baseBean -> {
        };


        FormBody requestBody = new FormBody.Builder()
                .build();
        HttpMethods.getInstance().getDiaoChaQuZhengList(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);
    }
}
